VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DOMRecurse"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
' DOMRecurse.cls    July 1999  contact markb@orionstudios.com
' Encapsulates a method to recursively traverse an HTML document from a specified
'   Document Object Model (DOM) Node and raise an event for each Node encountered.
' Requires Project/References entry for
'   Microsoft HTML Object Library (MSHTML.tlb)
'=================================================================================
Public Event NodeEvent(DOMNode As MSHTML.IHTMLDOMNode, ByVal Depth As Long)

Public Function RecurseFromNode(StartNode As MSHTML.IHTMLDOMNode) As Boolean
    
    RaiseEvent NodeEvent(StartNode, 0)  ' Root Node for Recursion
    RecurseFromNode = ForEachNode(DOMNode:=StartNode, Depth:=1) ' Initiate Recursion
    
End Function

Private Function ForEachNode( _
            DOMNode As MSHTML.IHTMLDOMNode, _
            ByVal Depth As Long) As Boolean ' RECURSIVE

    On Error GoTo ForEachNode_Error
    
    Dim Result As Boolean   ' default function result = False
    Dim oNode As MSHTML.IHTMLDOMNode
    
    Set oNode = DOMNode.firstChild
    Do Until oNode Is Nothing
        RaiseEvent NodeEvent(oNode, Depth + 1)
        If oNode.hasChildNodes Then
            ForEachNode DOMNode:=oNode, Depth:=Depth + 1 ' Recursive call
        End If
        Set oNode = oNode.nextSibling
    Loop
    Result = True
    
ForEachNode_Exit:
    ForEachNode = Result
    Exit Function

ForEachNode_Error:
    Resume ForEachNode_Exit
    
End Function
